<?php
/**
 * 站点对象
 */
namespace logic\site;
class Site{
    
    private $siteId;
    private $info;
    public function __construct($siteId){
        $this->siteId = $siteId;
    }
    
    /**
     * 读取站点信息
     */
    public function getInfo(){
        if( !$this->info ){
            $info = D('Site','site')->find(['siteid'=>$this->siteId]);
            $this->info = $info;
        }
        return $this->info;
    }
    
    /**
     * 读取站点域名
     */
    public function getHost($channel = false){
        $channelList = ['admin','www']; //管理后台 /前端pc /前端wap [m]
        if( !in_array( $channel,$channelList) ) logicE('不支持的域名');
        $siteInfo = $this->getInfo();
        $host = $siteInfo['domaintype'] == 1 ? $siteInfo['domain'] : config('url.domain');        
        if( $channel ){
            if( $channel == 'admin' ) $reHost = 'http://admin.'.$host;
            if( $channel == 'www' ){
                if( $siteInfo['domaintype'] == 1 ){
                    $reHost = 'http://www.'.$host;
                }else{
                    $reHost = 'http://'.$siteInfo['domain'].'.'.config('url.domain');
                }
            }
        }
        return $reHost.'/';
    }
    
    
}